/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.web.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.losenote.base.LnConstrant;
import com.losenote.model.OperateContext;
import com.losenote.model.UserInfo;

/**
 * 基础控制器
 * 
 * @author danjingyu
 * @version $Id: BaseController.java, v 0.1 2013-10-26 下午9:31:08 danjingyu Exp $
 */
public class BaseController {

    private final static String USER_INFO = "USER_INFO";

    /**
     * 获取当前操作的上下文
     * 
     * @return
     */
    public static OperateContext getOperateContext(HttpServletRequest request) {

        HttpSession session = request.getSession();
        UserInfo userInfo = null;
        if (session.getAttribute(USER_INFO) == null) {
            userInfo = LnConstrant.ANONYMOUS;
        } else {
            userInfo = (UserInfo) session.getAttribute(USER_INFO);
        }
        OperateContext context = new OperateContext();
        String ip = request.getRemoteAddr();//返回发出请求的IP地址
        context.setIpAddress(ip);
        context.setUserInfo(userInfo);
        return context;
    }
}
